package com.hyz.service.impl;

import client.AssetClient;
import com.hyz.pojo.request.ApprovalResultRequest;
import com.hyz.pojo.response.AssetSecondmentResponse;
import com.hyz.service.ChargeLeaderService;
import com.hyz.util.AssetSecondmentUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.ResponseResult;
import pojo.asset.assetSecondment.AssetSecondment;
import pojo.asset.assetSecondment.AssetSecondmentResult;

import java.util.List;

/**
 * @author HGD
 * @date 2022/10/10 0:16
 */
@Service
public class ChargeLeaderServiceImpl implements ChargeLeaderService {
    @Autowired
    private AssetClient assetClient;
    @Autowired
    private AssetSecondmentUtils asUtils;

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> clGetAssetSecondments() {
        ResponseResult<List<AssetSecondment>> result = assetClient.clGetAssetSecondments();
        return asUtils.getAssetSecondmentResponse(result);
    }

    @Override
    public ResponseResult<List<AssetSecondmentResponse>> clUpdateAssetSecondment(ApprovalResultRequest request) {
        int code = 200;
        ResponseResult<String> result = assetClient.clUpdateAssetSecondment(request.getApprovalId(),
                request.getResult() ? AssetSecondmentResult.CHARGE_LEADER_AGREE : AssetSecondmentResult.FAILED);
        if (result.getStatus() != code) {
            return new ResponseResult<>(result.getStatus(), result.getMsg());
        }
        return clGetAssetSecondments();
    }
}
